package com.cj.item.web;

import com.cj.common.dto.PageDTO;
import com.cj.item.constants.MqConstants;
import com.cj.item.pojo.Item;
import com.cj.item.service.IItemService;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@RestController
@RequestMapping("item")
public class ItemController {

    @Autowired
    private IItemService itemService;



    @GetMapping("list")
    public PageDTO<Item> pageQuery(@RequestParam Integer page, @RequestParam Integer size){
        return itemService.pageQuery(page,size);

    }

    @GetMapping("{id}")
    public Item query(@PathVariable Long id){
        return itemService.getById(id);

    }

    @PostMapping
    public void  addItem(@RequestBody Item item){
        item.setCreateTime(new Date());
        item.setUpdateTime(new Date());
        item.setStatus(2);
        itemService.save(item);


    }


    @PutMapping("/status/{id}/{status}")
    public void updateItemStatus(@PathVariable Long id,@PathVariable Integer status){
        itemService.updateItemById(id,status);

    }

    @PutMapping
    public void updateItem(@RequestBody Item item){
        item.setUpdateTime(new Date());
        itemService.updateById(item);

    }
    @DeleteMapping("{id}")
    public void deleteItemById(@PathVariable Long id){
        itemService.removeById(id);

    }
}
